package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpExpr;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

//员工管理的controller
@RestController
public class EmpController {
    //分页查询的controller
        @Autowired
    EmpService es;
    @GetMapping(value ="/emps2")
    //此处通过注解设置默认值
    public Result page(@RequestParam(defaultValue = "1")Integer page,
    @RequestParam(defaultValue = "10")Integer pageSize){
        return Result.success(es.onepage(page,pageSize));
    }
    //条件分页查询
    //只要保证形参和请求的参数一致，就不用考虑添加额外的注解了
    @GetMapping("/emps")
    public Result conditionfind(EmpQueryParam eqp){
        return Result.success(es.confind(eqp));
    }
    //插入员工
    @PostMapping("/emps")
    public Result insert(@RequestBody Emp e1){
        es.insertemp(e1);
        return Result.success();
    }
    //删除员工
    @DeleteMapping("/emps")
    public Result delete(@RequestParam List<Integer> ids) {
        es.delete(ids);
        return Result.success();
    }
    //查询员工的第一步：查询回显
    @GetMapping("/emps/{id}")
    public Result find (@PathVariable("id") Integer id){
        return Result.success(es.findemp(id));
    }
    //修改员工信息
    @PutMapping("/emps")
    public Result change(@RequestBody Emp emp){
        es.changeemp(emp);
        return Result.success();
    }
    //查询全部员工
    @GetMapping("/emps/list")
    public Result getallemp(){
      List<Emp> allemplist=es.getallemp();
      return Result.success(allemplist);
    }

}
